package com.cw.java8.ref;

import com.cw.java8.functionInterface.MyLogger;
import com.cw.java8.functionInterface.MyPrint;

/**
 * 方法引用演示
 */
public class MethodRef {

    public static void log() {
        System.out.println("方法引用实现log...............");
    }

    public void log2() {
        System.out.println("方法引用实现log2...............");
    }

    public void run() {
        System.out.println("方法引用实现线程.......");
    }

    /**
     * main方法入口
     *
     * @param args
     */
    public static void main(String[] args) {

        //lambda表达式： 参数列表 -> {语句块}
        MyLogger myLogger = () -> System.out.println("lambda表达式实现log...............");
        myLogger.log();

        //看能否采用方法引用实现
        MyLogger myLogger2 = MethodRef :: log;
        myLogger2.log();

        //看能否采用方法引用实现
        MethodRef methodRef = new MethodRef();
        MyLogger myLogger3 = methodRef :: log2;
        myLogger3.log();


        Thread thread2 = new Thread(() -> {
            System.out.println("lambda表达式实现线程.......");
        });
        thread2.start();

        //方法引用实现
        MethodRef methodRef1 = new MethodRef();
        Thread thread = new Thread(methodRef1 :: run);
        thread.start();


        MyPrint myPrint = (String msg) -> {
            System.out.println("打印：" + msg);
        };
        myPrint.print("https://www.tmooc.cn");

        //方法引用实现
        MyPrint myPrint2 = System.out :: println;
        myPrint2.print("方法引用打印:https://www.tmooc.cn");
    }
}
